package com.lww.feature.test.list;

import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import org.junit.Test;

import java.util.Arrays;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

/**
 * @author yi an
 * @date 2017/3/30
 */
public class test {

    @Test
    public void testSuavaSub() {
        List<Integer> list = Arrays.asList(1, 2, 3, 5, 6, 7, 8, 9, 0, 5, 0, 10, 12);
        Iterable<List<Integer>> lists = Iterables.paddedPartition(list, 5);
        for (Iterator it = lists.iterator(); it.hasNext(); ) {
            System.out.println(it.next());
        }
        Iterable<List<Integer>> lists2 = Iterables.partition(list, 5);
        for (Iterator it = lists2.iterator(); it.hasNext(); ) {
            System.out.println(it.next());
        }
        List<List<Integer>> lists3 = Lists.partition(list, 5);
        for (Iterator it = lists3.iterator(); it.hasNext(); ) {
            System.out.println(it.next());
        }
    }

    @Test
    public void listAddAllTest() {
        List<Integer> list = Arrays.asList(1, 2, 3, 5, 6, 7, 8, 9, 0, 5, 0, 10, 12);
        list.addAll(null);
        System.out.println(list);
    }


    @Test
    public void listAddBeforeTest() {
        LinkedList<Integer> list = Lists.newLinkedList();
        list.add(0,2);
        list.add(0,1);
        list.add(0,0);
        list.add(0,-1);
        System.out.println(list);
    }
}
